////////////////////////////////////////////////////////////
// Workfile : Writer.cpp
// Author : Thomas Pfeiffer
// Date : 31.10.2012
// Description : Implementation of the abstract Writer class
////////////////////////////////////////////////////////////

#include <iostream>
#include <fstream>
#include <string>
#include "IWrite.h"
#include "Writer.h"

void Writer::WriteFile( std::string const& filename, IWrite* data ) const
{
	std::ofstream myfile;
	myfile.open (filename);

	if (myfile.fail()) {
		throw "File could not be opened";
	}

	bool writeheader = true;

	IWrite::TAddressNamesMap const* addresses = data->getAddressesWithNames();
	IWrite::TAddressNamesMap::const_iterator it = addresses->begin();

	for (; it != addresses->end(); ++it) {
		DoWrite(myfile, it->first, it->second, writeheader);
		writeheader = false;
	}

	myfile.close();
}